package com.qmgyl.marketshop.api;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.qmfresh.service.common.dto.ListWithPage;
import com.qmfresh.service.entity.ProductSsu;
import com.qmfresh.service.entity.ProductSsuPrice;
import com.qmfresh.service.shop.facade.dto.ShopSsuQuery;
import com.qmgyl.marketshop.common.HttpUtils;
import com.qmgyl.marketshop.vo.ServiceResult;

public class ProductServiceApi {

	private String serviceUrl;

	public String getServiceUrl() {
		return serviceUrl;
	}

	public void setServiceUrl(String serviceUrl) {
		this.serviceUrl = serviceUrl;
	}
	
	/**
	 * 店仓ssu列表
	 * @param query
	 * @return
	 */
	public ListWithPage<ProductSsu> listProductSsu(ShopSsuQuery query){
		
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/productSsuList",query);
		System.out.println(result);
		ServiceResult<ListWithPage<ProductSsu>> sr = JSONObject.parseObject(result, new TypeReference<ServiceResult< ListWithPage<ProductSsu>>>(){});
		return sr.getBody();
	}
	
	/**
	 * 官方ssu列表
	 * @param query
	 * @return
	 */
	public ListWithPage<ProductSsu> listProSsu(ShopSsuQuery query){
		
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/proSsuList",query);
		System.out.println(result);
		ServiceResult<ListWithPage<ProductSsu>> sr = JSONObject.parseObject(result, new TypeReference<ServiceResult< ListWithPage<ProductSsu>>>(){});
		return sr.getBody();
	}
	
	/**
	 * ssu价格列表
	 * @param query
	 * @return
	 */
	public ListWithPage<ProductSsuPrice> listSsuPrice(ShopSsuQuery query){
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/productSsuPriceList",query);
		System.out.println(result);
		ServiceResult<ListWithPage<ProductSsuPrice>> sr = JSONObject.parseObject(result, new TypeReference<ServiceResult< ListWithPage<ProductSsuPrice>>>(){});
		return sr.getBody();
	}
	
	public boolean modifyPrice(ProductSsuPrice productSsuPrice){
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/modifyPrice",productSsuPrice);
		System.out.println(result);
		ServiceResult sr = JSONObject.parseObject(result,ServiceResult.class);
		return sr.getSuccess();
	}
	
	public boolean batchOnline(ProductSsuPrice[] productSsuPrices){
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/batchOnline",productSsuPrices);
		System.out.println(result);
		ServiceResult sr = JSONObject.parseObject(result,ServiceResult.class);
		return sr.getSuccess();
	}
	
	public boolean batchOffline(ProductSsuPrice[] productSsuPrices){
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/batchOffline",productSsuPrices);
		System.out.println(result);
		ServiceResult sr = JSONObject.parseObject(result,ServiceResult.class);
		return sr.getSuccess();
	}
	
	public boolean batchCopySsu(ProductSsu[] productSsus){
		String result = HttpUtils.postRequestBody(serviceUrl + "/shop/ssu/batchCopySsu",productSsus);
		System.out.println(result);
		ServiceResult sr = JSONObject.parseObject(result,ServiceResult.class);
		return sr.getSuccess();
	}
	
}
